<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var rg = /[abc]/;   //表示验证字符串只要有a 或者 b 或者c
        var rge = /^[abc]$/;   //只验证 a或者b或者c
        var re = /^[a-z]$/;   //可以验证a到z  26个英文字母  -表示一个范围

        //字符组合
        var rge2 = /^[a-zA-Z0-9_-]$/
        console.log(rge2.test(0));
        console.log(rge2.test('a'));
        console.log(rge2.test('B'));
        console.log(rge2.test('-'));
        console.log(rge2.test('_'));
        console.log(rge2.test('!'));

        console.log('--------------------------');

        //[]里面开头添加^表示取反
        var rge3 = /^[^a-zA-Z0-9_-]$/
        console.log(rge3.test(0));
        console.log(rge3.test('a'));
        console.log(rge3.test('B'));
        console.log(rge3.test('-'));
        console.log(rge3.test('_'));
        console.log(rge3.test('!'));
    </script>
</body>

</html>